from bs4 import BeautifulSoup

with open("../templates/page.html", "r+", encoding='utf-8') as html:
    html_bf = BeautifulSoup(html, 'lxml')
    divs = html_bf.select('.chart-container') # 根据css定位标签，选中图像的父节点标签
    divs[0]["style"] = "width:50%;height:50%;position:absolute;top:2%;left:40%;border-style:dashed;border-color:#444444;border-width:0px;"
    divs[1]["style"] = "width:50%;height:100%;position:absolute;top:0%;left:25%;border-style:solid;border-color:#444444;border-width:0px;"
    divs[2]["style"] = "width:35%;height:60%;position:absolute;top:45%;left:65%;border-style:solid;border-color:#444444;border-width:0px;"
    divs[3]["style"] = "width:41%;height:53%;position:absolute;top:50%;left:1%;border-style:solid;border-color:#444444;border-width:0px;"
    divs[4]["style"] = "width:35%;height:55%;position:absolute;top:0%;left:68%;border-style:solid;border-color:#444444;border-width:0px;"
    divs[5]["style"] = "width:35%;height:50%;position:absolute;top:0%;left:0%;border-style:solid;border-color:#444444;border-width:0px;"
    body = html_bf.find("body") # 根据标签名称定位到body标签
#     body["style"] = "background-color:#CCCCCC;" # 修改背景颜色
    body["style"] = "background-color:#44cef6;" # 修改背景颜色
#     body["style"] = "background-image: url(./a.jpg);" # 修改背景颜色
    html_new = str(html_bf) # 将BeautifulSoup对象转换为字符
    html.seek(0, 0) # 光标移动至
    html.truncate() # 删除光标后的所有字符内容
    html.write(html_new) # 将由BeautifulSoup对象转换得到的字符重新写入html文件
    html.close()